package com.hupu.jrs.ui.splash

import android.text.TextUtils
import android.widget.FrameLayout
import com.hupu.jrs.R
import com.hupu.jrs.ui.BaseActivity
import com.hupu.jrs.ui.main.MainActivity
import com.hupu.jrs.ui.messagelist.MessageActivity
import javax.inject.Inject
import butterknife.BindView
import butterknife.ButterKnife

/**
 * Created by sll on 2016/3/11.
 */
class SplashActivity : BaseActivity(), SplashContract.View {

    @BindView(R.id.splash)
    internal var splash: FrameLayout? = null

    @Inject
    internal var mPresenter: SplashPresenter? = null

    protected override val isApplyStatusBarTranslucency: Boolean
        get() = true

    protected override val isApplyStatusBarColor: Boolean
        get() = false

    override fun initContentView(): Int {
        return R.layout.activity_splash
    }

    override fun initInjector() {
        DaggerSplashComponent.builder()
                .applicationComponent(applicationComponent)
                .activityModule(activityModule)
                .splashModule(SplashModule(this))
                .build()
                .inject(this)
    }

    override fun initUiAndListener() {
        ButterKnife.bind(this)
        mPresenter!!.attachView(this)
        mPresenter!!.initUmeng()
        mPresenter!!.initHuPuSign()
    }

    override fun showMainUi() {
        MainActivity.startActivity(this@SplashActivity)
        val action = intent.action
        if (TextUtils.equals(action, ACTION_NOTIFICATION_MESSAGE)) {
            MessageActivity.startActivity(this@SplashActivity)
        }
        finish()
    }

    override fun onDestroy() {
        super.onDestroy()
        mPresenter!!.detachView()
    }

    companion object {

        val ACTION_NOTIFICATION_MESSAGE = "com.gzsll.hupu.ACTION_NOTIFICATION_MESSAGE"
    }
}
